package LeetCode.leetcode;

/**
 * 有序数组去重
 * Remove Duplicates from Sorted Array
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/2
 * @time: 12:27
 */
public class Test26删除排序数组中的重复项 {
    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        System.out.println(removeDuplicates(nums));
    }
    public static int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {
               continue;
            } else {
                nums[count++] = nums[i];
            }
        }
        return count;
    }
}
